<h2><?= esc($title) ?></h2>

<!-- 添加创建新闻的链接 -->
<p>
    <a href="/news/create" class="btn btn-primary">
        <i class="bi bi-plus-circle"></i> Create New News Item
    </a>
</p>

<?php if (!empty($news) && is_array($news)): ?>
    <div class="accordion" id="newsAccordion">
        <?php foreach ($news as $index => $news_item): ?>
            <div class="accordion-item">
                <h3 class="accordion-header" id="heading<?= $index ?>">
                    <button class="accordion-button <?= $index > 0 ? 'collapsed' : '' ?>" 
                            type="button" 
                            data-bs-toggle="collapse" 
                            data-bs-target="#collapse<?= $index ?>" 
                            aria-expanded="<?= $index === 0 ? 'true' : 'false' ?>" 
                            aria-controls="collapse<?= $index ?>">
                        <i class="bi bi-newspaper me-2"></i>
                        <?= esc($news_item->title) ?>
                    </button>
                </h3>
                <div id="collapse<?= $index ?>" 
                     class="accordion-collapse collapse <?= $index === 0 ? 'show' : '' ?>" 
                     aria-labelledby="heading<?= $index ?>" 
                     data-bs-parent="#newsAccordion">
                    <div class="accordion-body">
                        <p><?= esc($news_item->body) ?></p>
                        <div class="news-actions">
                            <a href="/news/<?= esc($news_item->slug, 'url') ?>" class="btn btn-info btn-sm">
                                <i class="bi bi-eye"></i> View Article
                            </a>
                            <a href="/news/delete/<?= $news_item->id ?>" class="btn btn-danger btn-sm" 
                               onclick="return confirm('Are you sure you want to delete \"<?= esc($news_item->title) ?>\"?')">
                                <i class="bi bi-trash"></i> Delete
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
<?php else: ?>
    <div class="alert alert-info">
        <h4><i class="bi bi-info-circle"></i> No News</h4>
        <p>Unable to find any news for you. <a href="/news/create">Create the first news item</a>.</p>
    </div>
<?php endif; ?>


